<template>
<view>
	<view class="">
		<view class="vouchers">
			<view style="margin-right: 30rpx;">名称:</view>
			<view class="">{{coupon.name}}</view>
		</view>
		<view class="vouchers">
			<view style="margin-right: 30rpx;">金额:</view>
			<view style="color: red;font-size: 30rpx;font-weight: bold;">￥{{coupon.money}}</view>
		</view>
		<view class="vouchers">
			<view style="margin-right: 30rpx;">使用时间:</view>
			<view class="">{{coupon.end_time}}前使用</view>
		</view>
		<!-- <view class="vouchers">
			<view style="margin-right: 30rpx;">券号:</view>
			<view class="">YMC_5c929fb47235</view>
		</view> -->
		<view class="vouchers">
			<view style="margin-right: 30rpx;">满减:</view>
			<view class="">满{{coupon.satisfy_money}}减{{coupon.money}}元</view>
		</view>
	</view>
	<view class="button" v-if="verification">
		<button style="border:1rpx solid #120062;color: #120062;" @click="cancelVerification(0)">核销</button>
		<button  style="color: #ff0000;border:1rpx solid #ff0000;" @click="cancelVerification">拒绝核销</button>
	</view>
	<view v-if="!verification" style="text-align: center;color: #999;margin:50rpx 20rpx;font-size: 33rpx;">优惠券已核销</view>
</view>
</template>

<script>
export default {
  name: "checked-code",
  data(){
	  return {
		  verification:true,
		  coupon_id:'',
		  urlObj:'',
		  coupon:{},
		  id:''
	  }
  },
  onShow(){
	  this.getUserCoupon()
  },
  async onLoad(option) {
  	if ('scene' in option) {
  		const paramsStr = decodeURIComponent(options.scene)
  		this.urlObj = this.$currency.getQueryString2(paramsStr)
  		this.coupon_id = this.urlObj.id
  	} else {
  		this.urlObj = option
  		this.coupon_id = this.urlObj.id
  	}
	this.getUserCoupon()
  },
  methods:{
	  cancelVerification(e){
		  if(e==0){
			  this.verificationCoupon()
		  }else{
			  uni.navigateBack({
			  	delta:1
			  })
		  }
	  },
	  //优惠券详情
	  async getUserCoupon(id){
	  		  this.$http('/api/coupon/getUserCoupon', {
	  		  	id: this.coupon_id
	  		  }, "GET").then(res => {
	  		  	this.coupon=res
				this.id=res.id
				if(this.coupon.is_use==0){
					this.verification=true
				}else{
					this.verification=false
				}
				console.log(this.coupon);
	  		  })
	  },
	  //核销
	  async verificationCoupon(){
		  this.$http('/api/coupon/verificationCoupon', {
		  	id: this.id
		  }, "POST").then(res => {
		  	let data = res
		  	uni.showToast({
		  		title: res.message,
		  		icon: 'none',
		  		duration: 1500
		  	})
		  })
	  }
  }
}

</script>

<style lang="scss" scoped>
.button{
	display: flex;
	margin-top: 50rpx;
	
}
button{
		width: 300rpx;
		border: 1rpx solid transparent;
		background-color: #fff;
	}
	.vouchers{
		display: flex;
		/* margin: 20rpx ; */
		padding: 20rpx 40rpx;
		
		view:first-child{
			width: 130rpx;
			text-align-last: justify;
		}
	}
	
</style>
